package org.wmq.travelagency02.common;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.wmq.travelagency02.constant.RoleConstant;
import org.wmq.travelagency02.model.Entity.ChatUser;
import org.wmq.travelagency02.service.GuidebookService;
import org.wmq.travelagency02.service.TravellerService;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

@Component
public class ChatUserHelper {
    @Lazy
    @Autowired
    private TravellerService travellerService;
    @Lazy
    @Autowired
    private GuidebookService guidebookService;

    private Map<Byte, OperateChatUserInterface> map = new HashMap<>();

    @PostConstruct
    private void init(){
        this.map.put(RoleConstant.TRAVELLER, travellerService);
        this.map.put(RoleConstant.GUIDEBOOK, guidebookService);
    }

    public boolean addChatUserId(String chatUserId, Long id, Byte type) {
        return this.map.get(type).addChatUserId(chatUserId, id);
    }

    public ChatUser getChatUser(Long id, Byte type) {
        return this.map.get(type).getChatUser(id);
    }

}
